import 'package:flutter/material.dart';
import 'package:flutter_app/utils/windowUtil.dart';
import 'QianbaoDizhi.dart';
import 'package:flutter/services.dart';
import 'dart:async';      // 异步
class Member1 extends StatefulWidget {
  @override
  State<Member1> createState() => _Member1State();
}

class _Member1State extends State<Member1> {

  var platform =  MethodChannel("samples.flutter.io/battery");
  String _batteryLevel = "Unknown battery level.";
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new ListView(
        padding: EdgeInsets.all(0),
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
                left: 20.0, top: 50.0, right: 20.0, bottom: 50.0),
            color: Color(0xff2c2825),
            child: Column(
              children: <Widget>[
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Text(
                      "您好，世界",
                      style:
                          TextStyle(color: Color(0xffffffcb), fontSize: 20.0),
                    ),

                    Image.asset(
                      "images/setting.png",
                      width: 30.0,
                      height: 30.0,
                    )
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.only(left: 5.0, right: 5.0),
                      child: Text(
                        "认证商家",
                        style: TextStyle(fontSize: 15.0),
                      ),
                      decoration: BoxDecoration(
                          gradient: LinearGradient(
                              colors: [Color(0xFFffffed), Color(0xFFfde8b0)],
                              begin: FractionalOffset(0, 1),
                              end: FractionalOffset(1, 1)),
                          borderRadius: BorderRadius.circular(5.0)),
                    ),
                    SizedBox(
                      width: 20.0,
                    ),
                    Container(
                      padding: EdgeInsets.only(left: 5.0, right: 5.0),
                      child: Text(
                        "上海市节点",
                        style: TextStyle(fontSize: 15.0),
                      ),
                      decoration: BoxDecoration(
                          gradient: LinearGradient(
                              colors: [Color(0xFFffffed), Color(0xFFfde8b0)],
                              begin: FractionalOffset(0, 1),
                              end: FractionalOffset(1, 1)),
                          borderRadius: BorderRadius.circular(5.0)),
                    ),
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Column(
                      children: <Widget>[
                        Text(
                          "BBOSS资产",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                        SizedBox(
                          height: 5.0,
                        ),
                        Text(
                          "10086",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                      ],
                    ),
                    Column(
                      children: <Widget>[
                        Text(
                          "Token",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                        SizedBox(
                          height: 5.0,
                        ),
                        Text(
                          "98878",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                      ],
                    ),
                    Column(
                      children: <Widget>[
                        Text(
                          "粉丝",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                        SizedBox(
                          height: 5.0,
                        ),
                        Text(
                          "1900000",
                          style: TextStyle(color: Color(0xffffffcb)),
                        ),
                      ],
                    ),
                  ],
                )
              ],
            ),
          ),
          Container(
            height: 10.0,
            color: Color(0xffefefef),
          ),
          Container(
            padding: EdgeInsets.only(
                left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
            child: Column(
              children: <Widget>[
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: <Widget>[
                    Text(
                      "我的消费",
                      style: TextStyle(
                          color: Color(0xff000000),
                          fontSize: 19.0,
                          fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      width: 20.0,
                    ),
                    Container(
                      padding: EdgeInsets.only(bottom: 1.0),
                      child: Text(
                        "每笔消费都能记账",
                        style: TextStyle(color: Colors.grey, fontSize: 13.0),
                      ),
                    )
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                        width: (windowUtil.width - 40) / 4,
                        child: Column(
                          children: <Widget>[
                            Image.asset(
                              "images/daishiyong.png",
                              width: 40.0,
                              height: 40.0,
                              fit: BoxFit.fill,
                            ),
                            Text("待记账")
                          ],
                        ),
                      ),
                      onTap: () {

                        _getBatteryLevel();



                      },
                    ),
                    GestureDetector(
                      child: Container(
                        width: (windowUtil.width - 40) / 4,
                        child: Column(
                          children: <Widget>[
                            Image.asset(
                              "images/daipingjia.png",
                              width: 40.0,
                              height: 40.0,
                              fit: BoxFit.fill,
                            ),
                            Text("已记账")
                          ],
                        ),
                      ),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/yiquxiao.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("已取消")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/quanbu.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("全部")
                            ],
                          )),
                      onTap: () {},
                    ),
                  ],
                )
              ],
            ),
          ),
          Container(
            height: 10.0,
            color: Color(0xffefefef),
          ),
          Container(
            padding: EdgeInsets.only(
                left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
            child: Column(
              children: <Widget>[
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: <Widget>[
                    Text(
                      "我是商家",
                      style: TextStyle(
                          color: Color(0xff000000),
                          fontSize: 19.0,
                          fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      width: 20.0,
                    ),
                    Container(
                      padding: EdgeInsets.only(bottom: 1.0),
                      child: Text(
                        "每笔记账都代表收货",
                        style: TextStyle(color: Colors.grey, fontSize: 13.0),
                      ),
                    )
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                        width: (windowUtil.width - 40) / 4,
                        child: Column(
                          children: <Widget>[
                            Image.asset(
                              "images/shangjiama.png",
                              width: 40.0,
                              height: 40.0,
                              fit: BoxFit.fill,
                            ),
                            Text("商家码")
                          ],
                        ),
                      ),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/daishiyong.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("待记账")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/daipingjia.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("已记账")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/quanbu.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("全部账单")
                            ],
                          )),
                      onTap: () {},
                    ),
                  ],
                )
              ],
            ),
          ),
          Container(
            height: 10.0,
            color: Color(0xffefefef),
          ),
          Container(
            padding: EdgeInsets.only(
                left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
            child: Column(
              children: <Widget>[
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: <Widget>[
                    Text(
                      "我的工具",
                      style: TextStyle(
                          color: Color(0xff000000),
                          fontSize: 19.0,
                          fontWeight: FontWeight.bold),
                    ),
                    SizedBox(
                      width: 20.0,
                    ),
                    Container(
                      padding: EdgeInsets.only(bottom: 1.0),
                      child: Text(
                        "你的贴心助手",
                        style: TextStyle(color: Colors.grey, fontSize: 13.0),
                      ),
                    )
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/shangjiaruzhu.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("商家入驻")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/qianbaodizhi.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("钱包地址")
                            ],
                          )),
                      onTap: () {
                        Navigator.push(context, new MaterialPageRoute(builder: (con){
                          return new QianbaoDizhi();
                        }));

                      },
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/daizhifu.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("聊天钱包")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/bboszhuanzhang.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("BBOSS转账")
                            ],
                          )),
                      onTap: () {},
                    ),
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/chongzhi.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("BBOSS充值")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/wodefenxiang.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("我的分享")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/xitong.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("系统帮助")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/zhanghaobangding.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("账号绑定")
                            ],
                          )),
                      onTap: () {},
                    ),
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/safe.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("账号安全")
                            ],
                          )),
                      onTap: () {},
                    ),
                    GestureDetector(
                      child: Container(
                          width: (windowUtil.width - 40) / 4,
                          child: Column(
                            children: <Widget>[
                              Image.asset(
                                "images/tuichuzhanghao.png",
                                width: 40.0,
                                height: 40.0,
                                fit: BoxFit.fill,
                              ),
                              Text("退出")
                            ],
                          )),
                      onTap: () {},
                    ),
                    Opacity(
                        opacity: 0.0,
                        child: Container(
                          width: (windowUtil.width - 40) / 4,
                        )),
                    Opacity(
                      opacity: 0.0,
                      child: Container(
                        width: (windowUtil.width - 40) / 4,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }


  Future<Null> _getBatteryLevel() async {
    String batteryLevel;
    try{
      print('dart-_getBatteryLevel');
      // 在通道上调用此方法
      final int result = await platform.invokeMethod('getBatteryLevel');
      batteryLevel = 'Battery level at $result % .';
    } on PlatformException catch (e){
      batteryLevel = "Failed to get battery level: '${e.message}'.";
    }
    setState(() {
      _batteryLevel = batteryLevel;
    });
  }


}
